# Contributor: wener <wenermail@gmail.com>
# Maintainer: wener <wenermail@gmail.com>
pkgname=thanos
pkgver=0.23.1
pkgrel=3
pkgdesc="Highly available Prometheus setup with long term storage capabilities. CNCF Sandbox project."
url="https://github.com/thanos-io/thanos"
license="Apache-2.0"
arch="all !riscv64" # prometheus
install="thanos.pre-install"
makedepends="go prometheus tzdata"
subpackages="$pkgname-openrc"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/thanos-io/thanos/archive/v$pkgver.tar.gz
	thanos.initd
	thanos.confd
	"

build() {
	GOFLAGS="$GOFLAGS -trimpath"
	GOLDFLAGS="
		-extldflags '-static'
		-X github.com/prometheus/common/version.Version=$pkgver
		-X github.com/prometheus/common/version.Revision=AlpineLinux
		-X github.com/prometheus/common/version.Branch=master
		-X github.com/prometheus/common/version.BuildUser=$USER@$HOSTNAME
		-X github.com/prometheus/common/version.BuildDate=$(date -u "+%Y%m%d-%H:%M:%S" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	"

	go build \
		$GOFLAGS \
		-ldflags "$GOLDFLAGS" \
		./cmd/thanos
}

check() {
	# some tests need external storage credentials or running server
	# pkg/cacheutil go 1.15 compact
	# pkg/pool alloc too much memory
	go test $(go list ./... | grep -v \
		-e 'test/e2e' \
		-e 'pkg/shipper' \
		-e 'pkg/store' \
		-e 'objstore/objtesting' \
		-e 'pkg/promclient' \
		-e 'pkg/rules' \
		-e 'pkg/compact' \
		-e 'pkg/block' \
		-e 'pkg/query' \
		-e 'pkg/cacheutil' \
		-e 'pkg/pool' \
		-e 'pkg/targets' \
		-e 'pkg/metadata' \
		)
}

package() {
	install -Dm755 thanos "$pkgdir"/usr/bin/thanos

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
50a6ba056ace9359d86ada006cb16ad810f79745b979ba405c61274a42d2aeb7e47ed65377777c619469d3055b3ce30bcd9f04ca0225dec9777e288a979ffacb  thanos-0.23.1.tar.gz
8407adbc29d90d36550ad16555d0b881d1d1745fba7bf5f4bd4a66bdf4abe196321106881dbba569c7e123d6abfbe78714b6e108b1e3c69b051270c3a46ba5c8  thanos.initd
c1bc9d71828b176eed964d5f673ea5e5d368f25ca21a3b12dcb8f8987f8bf12f35c06849d7fc4e6ffae52d98a5e636bdb63333930fe640c48e4d02a0b8db620a  thanos.confd
"
